package com.hspedu.poly_.Array;

public class PolyArray {
    public static void main(String[] args) {
        Person[] persons = new Person[5];

        persons[0] = new Person("jack",20);
        persons[1] = new Student("mary",18,100);
        persons[2] = new Student("smith",19,30.1);
        persons[3] = new Teacher("scott",30,20000);
        persons[4] = new Teacher("king",50,25000);

        for (int i = 0; i < persons.length; i++) {
            System.out.println(persons[i].say());
            System.out.println();
            if (persons[i] instanceof Student){
                Student student = (Student) persons[i];
                student.study();
                System.out.println();
            }else if (persons[i] instanceof Teacher){
                ((Teacher) persons[i]).teach();
            }
        }
    }
}
